﻿using System;
using System.Collections.Generic;
using GMME.Model.Rtm.Notify;
using GMME.Model.Rtm.Result;
using UnityEngine;

namespace GMME
{
#if UNITY_ANDROID
    public class CallbackHandlerForEditor : AndroidJavaProxy
#else
    public class CallbackHandlerForEditor
#endif
    {
        #region delegate

        //创建引擎
        public delegate void EngineCreateCompleteCallback(int code, string msg);

        public delegate void DestroyEngineCompleteCallback(int code, string msg);

        //屏蔽
        public delegate void MutePlayerCompleteCallback(string roomId, string openId, bool isMuted, int code,
            string msg);

        public delegate void MuteAllPlayersCompleteCallback(string roomId, List<string> openIds, bool isMuted, int code,
            string msg);

        //加入|切换|离开房间
        public delegate void JoinTeamRoomCompleteCallback(string roomId, int code, string msg);

        public delegate void SwitchRoomCompleteCallback(string roomId, int code, string msg);

        public delegate void LeaveRoomCompleteCallback(string roomId, int code, string msg);

        //创建或者加入国战房间
        public delegate void JoinNationalRoomCompleteCallback(string roomId, int code, string msg);

        //创建或者加入范围房间
        public delegate void JoinRangeRoomCompleteCallback(string roomId, int code, string msg);

        //修改房间
        public delegate void TransferOwnerCompleteCallback(string roomId, int code, string msg);

        //获取正在讲话玩家列表
        public delegate void OnSpeakersDetectionCompleteCallback(List<string> openIds);

        //获取正在讲话玩家列表(带玩家说话的音量)
        public delegate void OnSpeakersDetectionExCompleteCallback(List<VolumeInfo> userVolumeInfos);

        //禁言玩家
        public delegate void ForbidPlayerCompleteCallback(string roomId, string openIds, bool isForbidden, int code,
            string msg);

        public delegate void ForbidAllPlayersCompleteCallback(string roomId, List<string> openIds, bool isForbidden,
            int code, string msg);

        public delegate void ForbiddenByOwnerCompleteCallback(string roomId, List<string> openIds, bool isForbidden);

        //玩家上下线
        public delegate void PlayerOnlineCompleteCallback(string roomId, string openId);

        public delegate void PlayerOfflineCompleteCallback(string roomId, string openId);

        // 远端玩家的麦克风状态变化 
        public delegate void OnRemoteMicroStateChangedCompleteCallback(string roomId, string openId, bool isMute);

        //语音转文字
        public delegate void VoiceToTextCompleteCallback(string text, int code, string msg);


        // 语音消息上传|下载|录制回调
        public delegate void UploadAudioMsgFileCompleteCallback(string filePath, string fileId, int code, string msg);

        public delegate void DownloadAudioMsgFileCompleteCallback(string filePath, string fileId, int code, string msg);

        public delegate void RecordAudioMsgCompleteCallback(string filePath, int code, string msg);

        public delegate void PlayAudioMsgCompleteCallback(string filePath, int code, string msg);
        
        public delegate void StartDetectAudioFileCompleteCallback(string fileId, int code, string msg);

        public delegate void AudioClipStateChangedNotifyCallback(AudioPlayStateInfo audioPlayStateInfo);

        #region rtm

        public delegate void OnSubscribeRtmChannelCallback(SubscribeRtmChannelResult result);

        public delegate void OnUnSubscribeRtmChannelCallback(UnSubscribeRtmChannelResult result);

        public delegate void OnPublishRtmChannelMessageCallback(PublishRtmChannelMessageResult result);

        public delegate void OnPublishRtmPeerMessageCallback(PublishRtmPeerMessageResult result);

        public delegate void OnGetRtmChannelInfoCallback(GetRtmChannelInfoResult result);

        public delegate void OnReceiveRtmChannelMessageCallback(ReceiveRtmChannelMessageNotify notify);

        public delegate void OnReceiveRtmPeerMessageCallback(ReceiveRtmPeerMessageNotify notify);

        public delegate void OnRtmConnectionChangedCallback(RtmConnectionStatusNotify notify);

        public delegate void OnSetRtmChannelPlayerPropertiesCallback(SetRtmChannelPlayerPropertiesResult result);

        public delegate void OnGetRtmChannelPlayerPropertiesCallback(GetRtmChannelPlayerPropertiesResult result);

        public delegate void OnDeleteRtmChannelPlayerPropertiesCallback(DeleteRtmChannelPlayerPropertiesResult result);

        public delegate void OnSetRtmChannelPropertiesCallback(SetRtmChannelPropertiesResult result);

        public delegate void OnGetRtmChannelPropertiesCallback(GetRtmChannelPropertiesResult result);

        public delegate void OnDeleteRtmChannelPropertiesCallback(DeleteRtmChannelPropertiesResult result);

        public delegate void OnGetRtmChannelHistoryMessagesCallback(GetRtmChannelHistoryMessagesResult result);

        public delegate void OnRtmChannelPlayerPropertiesChangedCallback(RtmChannelPlayerPropertiesNotify result);

        public delegate void OnRtmChannelPropertiesChangedCallback(RtmChannelPropertiesNotify result);

        #endregion

        #endregion

        #region event

        public event EngineCreateCompleteCallback OnEngineCreateCompleteEvent;
        public event DestroyEngineCompleteCallback OnDestroyEngineCompleteEvent;

        public event MutePlayerCompleteCallback OnMutePlayerCompleteEvent;
        public event MuteAllPlayersCompleteCallback OnMuteAllPlayersCompleteEvent;

        public event JoinTeamRoomCompleteCallback OnJoinTeamRoomCompleteEvent;
        public event JoinNationalRoomCompleteCallback OnJoinNationalRoomCompleteEvent;
        public event JoinRangeRoomCompleteCallback OnJoinRangeRoomCompleteEvent;
        public event SwitchRoomCompleteCallback OnSwitchRoomCompleteEvent;
        public event LeaveRoomCompleteCallback OnLeaveRoomCompleteEvent;
        public event TransferOwnerCompleteCallback OnTransferOwnerCompleteEvent;

        public event OnSpeakersDetectionCompleteCallback OnSpeakersDetectionCompleteEvent;

        public event OnSpeakersDetectionExCompleteCallback OnSpeakersDetectionExCompleteEvent;

        public event ForbidPlayerCompleteCallback OnForbidPlayerCompleteEvent;
        public event ForbidAllPlayersCompleteCallback OnForbidAllPlayersCompleteEvent;
        public event ForbiddenByOwnerCompleteCallback OnForbiddenByOwnerCompleteEvent;

        public event VoiceToTextCompleteCallback OnVoiceToTextCompleteEvent;

        public event PlayerOfflineCompleteCallback OnPlayerOfflineCompleteEvent;
        public event PlayerOnlineCompleteCallback OnPlayerOnlineCompleteEvent;

        public event OnRemoteMicroStateChangedCompleteCallback OnRemoteMicroStateChangedCompleteEvent;
        
        public event UploadAudioMsgFileCompleteCallback OnUploadAudioMsgFileCompleteEvent;
        public event DownloadAudioMsgFileCompleteCallback OnDownloadAudioMsgFileCompleteEvent;
        public event RecordAudioMsgCompleteCallback OnRecordAudioMsgCompleteEvent;

        public event PlayAudioMsgCompleteCallback OnPlayAudioMsgCompleteEvent;

        public event StartDetectAudioFileCompleteCallback OnStartDetectAudioFileCompleteEvent;

        public event AudioClipStateChangedNotifyCallback OnAudioClipStateChangedNotifyEvent;

        #region rtm

        public event OnSubscribeRtmChannelCallback OnSubscribeRtmChannelEvent;
        public event OnUnSubscribeRtmChannelCallback OnUnSubscribeRtmChannelEvent;
        public event OnPublishRtmChannelMessageCallback OnPublishRtmChannelMessageEvent;
        public event OnPublishRtmPeerMessageCallback OnPublishRtmPeerMessageEvent;
        public event OnGetRtmChannelInfoCallback OnGetRtmChannelInfoEvent;
        public event OnReceiveRtmChannelMessageCallback OnReceiveRtmChannelMessageEvent;
        public event OnReceiveRtmPeerMessageCallback OnReceiveRtmPeerMessageEvent;
        public event OnRtmConnectionChangedCallback OnRtmConnectionChangedEvent;
        public event OnSetRtmChannelPlayerPropertiesCallback OnSetRtmChannelPlayerPropertiesEvent;
        public event OnGetRtmChannelPlayerPropertiesCallback OnGetRtmChannelPlayerPropertiesEvent;
        public event OnDeleteRtmChannelPlayerPropertiesCallback OnDeleteRtmChannelPlayerPropertiesEvent;
        public event OnSetRtmChannelPropertiesCallback OnSetRtmChannelPropertiesEvent;
        public event OnGetRtmChannelPropertiesCallback OnGetRtmChannelPropertiesEvent;
        public event OnDeleteRtmChannelPropertiesCallback OnDeleteRtmChannelPropertiesEvent;
        public event OnGetRtmChannelHistoryMessagesCallback OnGetRtmChannelHistoryMessagesEvent;
        public event OnRtmChannelPlayerPropertiesChangedCallback OnRtmChannelPlayerPropertiesChangedEvent;
        public event OnRtmChannelPropertiesChangedCallback OnRtmChannelPropertiesChangedEvent;

        #endregion

        #endregion

#if UNITY_ANDROID
        public CallbackHandlerForEditor() : base("com.huawei.game.gmme.handler.IGameMMEEventHandler")
        {
        }
#else
        public CallbackHandlerForEditor()
        {
        }
#endif

        /**
         * 创建游戏多媒体实例回调
         *
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onCreate(int code, string msg)
        {
            OnEngineCreateCompleteEvent?.Invoke(code, msg);
        }

        /**
         * 屏蔽单个玩家操作的回调
         *
         * @param roomId 房间ID
         * @param openId 被屏蔽的玩家id集合
         * @param isMuted 是否屏蔽
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onMutePlayer(string roomId, string openId, bool isMuted, int code, string msg)
        {
            Debug.LogFormat("handler onMutePlayer.roomId ={0}, isMuted={1}, code={2}, msg={3}", roomId, isMuted, code, msg);
            OnMutePlayerCompleteEvent?.Invoke(roomId, openId, isMuted, code, msg);
        }

        /**
         * 屏蔽所有玩家操作的回调
         *
         * @param roomId 房间ID
         * @param openIds 被屏蔽的玩家id集合
         * @param isMuted 是否屏蔽
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onMuteAllPlayers(string roomId, List<string> openIdList, bool isMuted, int code, string msg)
        {
            OnMuteAllPlayersCompleteEvent?.Invoke(roomId, openIdList, isMuted, code, msg);
        }

        /**
         * 创建或者加入小队房间回调
         *
         * @param roomId 房间ID
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onJoinTeamRoom(string roomId, int code, string msg)
        {
            Debug.LogFormat("handler onJoinTeamRoom.roomId ={0}, code={1}, msg={2}", roomId, code, msg);
            OnJoinTeamRoomCompleteEvent?.Invoke(roomId, code, msg);
        }

        /**
         * 创建或者加入国战房间回调
         *
         * @param roomId 房间ID
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onJoinNationalRoom(string roomId, int code, string msg)
        {
            Debug.LogFormat("handler onJoinNationalRoom.roomId ={0}, code={1}, msg={2}", roomId, code, msg);
            OnJoinNationalRoomCompleteEvent?.Invoke(roomId, code, msg);
        }

        /**
         * 创建或者加入范围房间回调
         *
         * @param roomId 房间ID
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onJoinRangeRoom(string roomId, int code, string msg)
        {
            Debug.LogFormat("handler onJoinRangeRoom.roomId ={0}, code={1}, msg={2}", roomId, code, msg);
            OnJoinRangeRoomCompleteEvent?.Invoke(roomId, code, msg);
        }

        /**
         * 切换房间
         *
         * @param roomId 房间ID
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onSwitchRoom(string roomId, int code, string msg)
        {
            Debug.LogFormat("handler onSwitchRoom.roomId ={0}, code={1}, msg={2}", roomId, code, msg);
            OnSwitchRoomCompleteEvent?.Invoke(roomId, code, msg);
        }

        /**
         * 离开房间
         *
         * @param roomId 房间ID
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onLeaveRoom(string roomId, int code, string msg)
        {
            Debug.LogFormat("handler onLeaveRoom.roomId ={0}, code={1}, msg={2}", roomId, code, msg);
            OnLeaveRoomCompleteEvent?.Invoke(roomId, code, msg);
        }

        /**
         * 正在输出音频用户
         *
         * @param openIds 多媒体账号列表
         */
        public void onSpeakersDetectionEx(List<VolumeInfo> volumeInfoList, List<string> openIdList)
        {
            OnSpeakersDetectionExCompleteEvent?.Invoke(volumeInfoList);
            OnSpeakersDetectionCompleteEvent?.Invoke(openIdList);
        }

        /**
         * 房主禁言单个玩家的回调
         *
         * @param roomId 房间ID
         * @param openId 被禁言的玩家id
         * @param isForbidden 是否禁言
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onForbidPlayer(string roomId, string openId, bool isForbidden, int code, string msg)
        {
            Debug.LogFormat("handler onForbidPlayer.roomId ={0}, isForbidden={1}, code={2}, msg={3} ",
                roomId, isForbidden, code, msg);
            OnForbidPlayerCompleteEvent?.Invoke(roomId, openId, isForbidden, code, msg);
        }

        /**
         * 房主禁言所有玩家的回调
         *
         * @param roomId 房间ID
         * @param openIds 被禁言的玩家id集合
         * @param isForbidden 是否禁言
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onForbidAllPlayers(string roomId, List<string> openIdList, bool isForbidden, int code, string msg)
        {
            OnForbidAllPlayersCompleteEvent?.Invoke(roomId, openIdList, isForbidden, code, msg);
        }

        /**
         * 语音转文本事件
         *
         * @param text 语音转换后的文本
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onVoiceToText(string text, int code, string msg)
        {
            Debug.LogFormat("handler onVoiceToText. code={0}, msg={1} ",code, msg);
            OnVoiceToTextCompleteEvent?.Invoke(text, code, msg);
        }

        /**
         * 加入房间成功后，通知房间内已加入用户的回调
         *
         * @param roomId 房间ID
         * @param openId 玩家账号
         */
        public void onPlayerOnline(string roomId, string openId)
        {
            Debug.LogFormat("handler onPlayerOnline. roomId={0}", roomId);
            OnPlayerOnlineCompleteEvent?.Invoke(roomId, openId);
        }

        /**
         * 用户离开房间回调
         *
         * @param roomId 房间ID
         * @param openId 玩家账号
         */
        public void onPlayerOffline(string roomId, string openId)
        {
            Debug.LogFormat("handler onPlayerOffline. roomId={0}", roomId);
            OnPlayerOfflineCompleteEvent?.Invoke(roomId, openId);
        }

        /**
         * 玩家（房主）修改房间回调
         *
         * @param roomId 房间ID
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onTransferOwner(string roomId, int code, string msg)
        {
            Debug.LogFormat("handler onTransferOwner.roomId ={0}, code={1}, msg={2} ", roomId, code, msg);
            OnTransferOwnerCompleteEvent?.Invoke(roomId, code, msg);
        }

        /**
         * 远端玩家的麦克风状态回调
         *
         * @param roomId 房间ID
         * @param openId 玩家账号
         * @param isMute 是否禁麦
         */
        public void onRemoteMicroStateChanged(string roomId, string openId, bool isMute)
        {
            Debug.LogFormat("handler onRemoteMicroStateChanged. roomId={0}, isMute={1} ", roomId,
                isMute);
            OnRemoteMicroStateChangedCompleteEvent?.Invoke(roomId, openId, isMute);
        }


        /**
         * 语音消息上传回调
         *
         * @param filePath 文件路径
         * @param fileId 文件ID
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onUploadAudioMsgFile(string filePath, string fileId, int code, string msg)
        {
            Debug.LogFormat("handler onUploadAudioMsgFile.");
            OnUploadAudioMsgFileCompleteEvent?.Invoke(filePath, fileId, code, msg);
        }

        /**
         * 语音消息下载回调
         *
         * @param filePath 文件路径
         * @param fileId 文件ID
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onDownloadAudioMsgFile(string filePath, string fileId, int code, string msg)
        {
            Debug.LogFormat("handler onDownloadAudioMsgFile.");
            OnDownloadAudioMsgFileCompleteEvent?.Invoke(filePath, fileId, code, msg);
        }

        /**
         * 语音消息录制回调
         *
         * @param filePath 文件路径
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onRecordAudioMsg(string filePath, int code, string msg)
        {
            Debug.LogFormat("handler onRecordAudioMsg.");
            OnRecordAudioMsgCompleteEvent?.Invoke(filePath, code, msg);
        }

        public void onPlayAudioMsg(string filePath, int code, string msg)
        {
            Debug.LogFormat("handler onPlayAudioMsg.");
            OnPlayAudioMsgCompleteEvent?.Invoke(filePath, code, msg);
        }
        
        public void onStartDetectAudioFile(string fileId, int code, string msg)
        {
            Debug.LogFormat("handler onStartDetectAudioFile.");
            OnStartDetectAudioFileCompleteEvent?.Invoke(fileId, code, msg);
        }

        public void onAudioClipStateChangedNotify(AudioPlayStateInfo audioPlayStateInfo)
        {
            OnAudioClipStateChangedNotifyEvent?.Invoke(audioPlayStateInfo);
        }

        /**
         * 销毁游戏多媒体实例回调
         *
         * @param code 结果码
         * @param msg 处理结果信息
         */
        public void onDestroy(int code, string msg)
        {
            Debug.LogFormat("handler onDestroy. code={0}, msg={1} ", code, msg);
            OnDestroyEngineCompleteEvent?.Invoke(code, msg);
        }

        public void onSpeakersDetectionExComplete(List<VolumeInfo> list)
        {
            OnSpeakersDetectionExCompleteEvent?.Invoke(list);
        }

        public void onForbiddenByOwnerComplete(string roomId, List<string> openIdList, bool isForbidden)
        {
            OnForbiddenByOwnerCompleteEvent?.Invoke(roomId, openIdList, isForbidden);
        }


        #region rtm

        /**
         * 订阅RTM频道回调
         *
         * @param result 订阅RTM频道结果
         */
        public void onSubscribeRtmChannel(SubscribeRtmChannelResult result)
        {
            OnSubscribeRtmChannelEvent?.Invoke(result);
        }

        /**
         * 取消订阅RTM频道回调
         *
         * @param result 取消订阅RTM频道结果
         */
        public void onUnSubscribeRtmChannel(UnSubscribeRtmChannelResult result)
        {
            OnUnSubscribeRtmChannelEvent?.Invoke(result);
        }

        /**
         * 发布RTM频道消息回调
         *
         * @param result 发布RTM频道消息结果
         */
        public void onPublishRtmChannelMessage(PublishRtmChannelMessageResult result)
        {
            OnPublishRtmChannelMessageEvent?.Invoke(result);
        }

        /**
         * 发布RTM点对点消息回调
         *
         * @param result 发布RTM点对点消息结果
         */
        public void onPublishRtmPeerMessage(PublishRtmPeerMessageResult result)
        {
            OnPublishRtmPeerMessageEvent?.Invoke(result);
        }

        /**
         * 获取RTM频道信息回调
         *
         * @param result 获取RTM频道信息结果
         */
        public void onGetRtmChannelInfo(GetRtmChannelInfoResult result)
        {
            OnGetRtmChannelInfoEvent?.Invoke(result);
        }

        /**
         * 接收RTM频道信息通知
         *
         * @param notify 接收RTM频道信息结果
         */
        public void onReceiveRtmChannelMessage(ReceiveRtmChannelMessageNotify notify)
        {
            OnReceiveRtmChannelMessageEvent?.Invoke(notify);
        }

        /**
         * 接收RTM点对点信息通知
         *
         * @param notify 接收RTM点对点信息结果
         */
        public void onReceiveRtmPeerMessage(ReceiveRtmPeerMessageNotify notify)
        {
            OnReceiveRtmPeerMessageEvent?.Invoke(notify);
        }

        /**
         * RTM连接状态通知
         *
         * @param notify RTM连接状态结果
         */
        public void onRtmConnectionChanged(RtmConnectionStatusNotify notify)
        {
            OnRtmConnectionChangedEvent?.Invoke(notify);
        }

        /**
         * 设置频道内玩家属性结果回调
         *
         * @param result 设置频道内玩家属性结果
         */
        public void onSetRtmChannelPlayerProperties(SetRtmChannelPlayerPropertiesResult result)
        {
            OnSetRtmChannelPlayerPropertiesEvent?.Invoke(result);
        }

        /**
         * 查询频道内玩家属性结果回调
         *
         * @param result 查询频道内玩家属性结果
         */
        public void onGetRtmChannelPlayerProperties(GetRtmChannelPlayerPropertiesResult result)
        {
            OnGetRtmChannelPlayerPropertiesEvent?.Invoke(result);
        }

        /**
         * 删除频道内玩家属性结果回调
         *
         * @param result 删除频道内玩家属性结果
         */
        public void onDeleteRtmChannelPlayerProperties(DeleteRtmChannelPlayerPropertiesResult result)
        {
            OnDeleteRtmChannelPlayerPropertiesEvent?.Invoke(result);
        }

        /**
         * 设置频道属性结果回调
         *
         * @param result 设置频道属性结果
         */
        public void onSetRtmChannelProperties(SetRtmChannelPropertiesResult result)
        {
            OnSetRtmChannelPropertiesEvent?.Invoke(result);
        }

        /**
         * 查询频道属性结果回调
         *
         * @param result 查询频道属性结果
         */
        public void onGetRtmChannelProperties(GetRtmChannelPropertiesResult result)
        {
            OnGetRtmChannelPropertiesEvent?.Invoke(result);
        }

        /**
         * 删除频道属性结果回调
         *
         * @param result 删除频道属性结果
         */
        public void onDeleteRtmChannelProperties(DeleteRtmChannelPropertiesResult result)
        {
            OnDeleteRtmChannelPropertiesEvent?.Invoke(result);
        }

        /**
         * 查询频道历史消息回调
         *
         * @param result 查询频道历史消息结果
         */
        public void onGetRtmChannelHistoryMessages(GetRtmChannelHistoryMessagesResult result)
        {
            OnGetRtmChannelHistoryMessagesEvent?.Invoke(result);
        }

        /**
         * 频道内玩家属性变更通知
         *
         * @param notify 频道内玩家属性变更
         */
        public void onRtmChannelPlayerPropertiesChanged(RtmChannelPlayerPropertiesNotify notify)
        {
            OnRtmChannelPlayerPropertiesChangedEvent?.Invoke(notify);
        }

        /**
         * 频道属性变更通知
         *
         * @param notify 频道属性变更
         */
        public void onRtmChannelPropertiesChanged(RtmChannelPropertiesNotify notify)
        {
            OnRtmChannelPropertiesChangedEvent?.Invoke(notify);
        }

        #endregion
    }
}